package tt.dz.appserver.dao.ext;

import java.util.List;

import org.apache.commons.collections.map.ListOrderedMap;
import org.springframework.stereotype.Repository;

import tt.dz.appserver.dao.base.BasisDao;
import tt.dz.appserver.entity.model.AppVersion;

/**
 * App版本操作Dao
 * 
 * @author Administrator
 *
 */
@Repository
public class AppVersionDao extends BasisDao<AppVersion> {

	/**
	 * 查询最新的app版本
	 * 
	 * @param osType
	 * @return
	 */
	public AppVersion findAppLatestVersionByOsType(Integer osType) {

		AppVersion appVersion = new AppVersion();
		appVersion.setOs_type(osType);

		List<AppVersion> appVersions = super.findExample(appVersion, 1, 1, "version_code", 0);

		if (appVersions.size() > 0) {
			return appVersions.get(0);
		}
		return null;
	}

	/**
	 * App版本增加
	 */
	public int addAppVersion(AppVersion appVersion) {

		return super.save(appVersion);

	}

	/**
	 * App版本删除
	 */
	public int delAppVersion(AppVersion appVersion) {

		return super.update(appVersion);

	}

	/** App版本更新 */
	public int updateAppVersion(AppVersion appVersion) {

		return super.update(appVersion);

	}

	/**
	 * 有效App版本查询
	 */
	public List<AppVersion> findAppVersionValid(Integer ostype) {

		Integer validflag = 1;
		ListOrderedMap map = new ListOrderedMap();
		if (ostype != null) {
			map.put("os_type", ostype);
		}
		map.put("valid_flag", validflag);

		return super.findListAutomaticOfClass(AppVersion.class, map, null, null, "os_type, release_time", 2);

	}
}
